<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
    </el-form>

    <!-- 全局居中容器 -->
    <div class="global-center">
      <!-- 标题文字 -->
      <div class="mb8 blue-text title-text">安 云 逸 图 书 馆 图 书 预 约</div>
      <!-- 报名按钮 -->
      <el-button
        type="primary"
        plain
        size="large"
        @click="handleAdd"
        v-hasPermi="['reservation:dept:add']"
        class="blue-text button-style"
      >
        预约
      </el-button>
    </div>

    <!-- 添加图书预约对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="读者ID" prop="userId">
          <el-input v-model="form.userId" placeholder="请输入读者ID" />
        </el-form-item>
        <el-form-item label="图书ID" prop="bookId">
          <el-input v-model="form.bookId" placeholder="请输入图书ID" />
        </el-form-item>
        <el-form-item label="预约时间" prop="expireTime">
          <el-date-picker clearable
            v-model="form.expireTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择预约时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="预约有效期" prop="reserveTime">
          <el-date-picker clearable
                          v-model="form.reserveTime"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="请选择预约有效期">
          </el-date-picker>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listDept, getDept, delDept, addDept, updateDept } from "@/api/reservation/dept";

export default {
  name: "Dept",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 图书预约表格数据
      deptList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userId: null,
        bookId: null,
        reserveTime: null,
        expireTime: null,
        status: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        userId: [
          { required: true, message: "读者ID不能为空", trigger: "blur" }
        ],
        bookId: [
          { required: true, message: "图书ID不能为空", trigger: "blur" }
        ],
        expireTime: [
          { required: true, message: "预约有效期不能为空", trigger: "blur" }
        ]
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询图书预约列表 */
    getList() {
      this.loading = true;
      listDept(this.queryParams).then(response => {
        this.deptList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        userId: null,
        bookId: null,
        reserveTime: null,
        expireTime: null,
        status: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加图书预约";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getDept(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改图书预约";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateDept(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addDept(this.form).then(response => {
              this.$modal.msgSuccess("提交成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除图书预约编号为"' + ids + '"的数据项？').then(function() {
        return delDept(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('reservation/dept/export', {
        ...this.queryParams
      }, `dept_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>


<style scoped>
/* 蓝色文字 + 加大字体 */
.blue-text {
  color: #409eff;
  font-size: 14px;
  font-weight: 500;
}

/* 全局居中容器 */
.global-center {
  display: flex;
  min-height: 100vh;
  justify-content: center;
  align-items: center;
  flex-direction: column;
  margin: 16px 0;
  /* 老式浏览器兼容 */
  display: -ms-flexbox;
  -ms-flex-direction: column;
  -ms-flex-pack: center;
  -ms-flex-align: center;
}

/* 调整按钮和文字的行内布局 */
.el-row {
  display: inline-flex;
  flex-direction: row;
  align-items: center;
  gap: 10px;
}

/* 按钮居中子元素 */
.el-col {
  display: flex;
  justify-content: center;
}

/* 标题文字样式 */
.title-text {
  font-size: 50px;
  font-weight: 700;
  margin-bottom: 30px;
  transform: translateY(-150px);
  letter-spacing: 8px; /* 增加文字间距 */
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.1); /* 轻微阴影 */
}

/* 按钮样式 */
.button-style {
  padding: 12px 32px;
  font-size: 20px;
  border-radius: 8px;
  transform: translateY(-150px);
  background-color: #409eff; /* 主色调 */
  color: white; /* 文字白色 */
  border: none; /* 移除边框 */
  transition: all 0.3s ease; /* 动画效果 */
}

.button-style:hover {
  background-color: #3080ee; /* 悬停时颜色加深 */
  transform: translateY(-152px); /* 轻微上浮 */
  box-shadow: 0 4px 12px rgba(64, 158, 255, 0.3); /* 阴影效果 */
}

.button-style:active {
  transform: translateY(-149px); /* 点击时下压 */
}
</style>
